<?php
// @formatter:off
/**
 * @file c.comic-info.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-16 23:56:49 +0000 (Sun, 16 Jun 2013) $
 *
 * $Id: c.comic-info.php 73 2013-06-16 23:56:49Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA1/themes/mdefault/controlers/contents/c.comic-info.php $
 */
// @formatter:on

global $wcComic;
global $wcReadRate;
global $wcTagsHolder;

if($wcProfile->allowedTo(WC_PERM_COMIC_VIEW)) {
	if($wcComic && $wcComic->ok()) {
		$wcThemeAssigns["PATH"] = "{$wcComic->directory()->name}/{$wcComic->name} (info)";
		$wcThemeAssigns["ACTIONCONTENT"] = "/contents/c.comic-info.html";
		$wcThemeAssigns["ACTIONPRESCRIPT"] = "/contents/c.comic-info.js";

		$paramsNoImg = requestParams(true, WC_ACTION_COMIC_SHOW, array());

		$wcThemeMobileDefault->addBarIcons(50, "IMAGE_BACK", "document.location.href='{$paramsNoImg}'", "{$this->uri()}/icons/table-icon.png");

		$wcThemeAssigns["id"] = $wcComic->id;
		$wcThemeAssigns["name"] = $wcComic->next_name ? $wcComic->next_name : $wcComic->name;
		$wcThemeAssigns["directory"] = $wcComic->directory()->name;
		if($wcComic->collection()) {
			$wcThemeAssigns["collection"] = $wcComic->collection()->name;
			$wcThemeAssigns["collection-id"] = $wcComic->collection()->id;
		}

		$global = $wcReadRate->comicReadRate($wcComic);
		$wcThemeAssigns["global-rate"] = $global["rate"];
		$wcThemeAssigns["global-reads"] = $global["reads"];
		$wcThemeAssigns["global-votes"] = $global["votes"];

		$personal = $wcReadRate->readRate($wcComic);
		$wcThemeAssigns["personal-rate"] = $personal["rate"]["rate"] ? $personal["rate"]["rate"] : 0;
		if($personal["read"]["read"] == "Y") {
			$wcThemeAssigns["personal-read"] = true;
		}

		$tags = array();
		foreach($wcTagsHolder->tagsOf($wcComic) as $tag) {
			$tags[] = array(
				"id" => $tag->id,
				"name" => $tag->name
			);
		}
		$wcThemeAssigns["tags"] = $tags;
	} else {
		$wcThemeAssigns["error-string"] = "Invalid comic";
		require "{$this->_themeRoot}/controlers/contents/c.500.php";
	}
} else {
	$wcThemeAssigns["error-string"] = "You're not allowed to open comics";
	require "{$this->_themeRoot}/controlers/contents/c.403.php";
}
?>